package com.wzm.api;

import com.wzm.pojo.Result;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import com.wzm.pojo.Rsp;
import com.wzm.pojo.WarehouseIn;

import java.util.HashMap;
import java.util.Map;

public class WarehouseInAPI extends ServiceAPI {


    public  WarehouseInAPI(String host,String port, String basePath) {
        super(host, basePath);
    }
    public  WarehouseInAPI() {
        super("192.168.3.38:7070","");
    }

    public Rsp addWarehouseIn(String number, String srcNumber, String source, String type, String warehouse,String warehouseRoom) {

        //获取请求体
        Map<String,String> param = new HashMap<>();
        param.put("number",number);
        param.put("srcNumber",srcNumber);
        param.put("source",source);
        param.put("type",type);
        param.put("warehouse",warehouse);
        param.put("warehouseRoom",warehouseRoom);
        //新建入库单
        Response rsp = getSpecificGiven().log().all().
                contentType(ContentType.JSON).
                body(param).
                when().
                post("/business/warehouseIn/add");
        rsp.then().log().all();
        logger.info(rsp.toString());
        //解析相应数据
        Rsp result = HTTPRspUtils.parseRspRst(rsp);


        return result;
    }

    public Result editWarehouseIn(String number, String srcNumber, String source, String type, String warehouse,String warehouseRoom) {

        //获取请求体
        WarehouseIn warehouseIn = new WarehouseIn();
        warehouseIn.setNumber(number);
        warehouseIn.setSrcNumber(srcNumber);
        warehouseIn.setSource(source);
        warehouseIn.setType(type);
        warehouseIn.setWarehouse(warehouse);
        warehouseIn.setWarehouseRoom(warehouseRoom);
        //新建入库单
        Response rsp = getSpecificGiven().log().all().
                contentType(ContentType.JSON).
                body(warehouseIn).
                when().
                post("/business/warehouseIn/edit");
        rsp.then().log().all();
        //解析相应数据
        Rsp<WarehouseIn> result = HTTPRspUtils.parseRspRst(rsp,WarehouseIn.class);
        Rsp<Result> r = rsp.path("");
        return r.isSuccess() ? r.getResult() : null;
    }


}
